package com.ljfiction.book.Dialog;

import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.TextView;

import com.ljfiction.book.R;


/**
 * Created by QAQ on 2017/3/14.
 */

public class DownLoadDialog {
    private Dialog mDialog;
    private Listener listener;
    private TextView tv_title;
    private TextView big_title;
    private Button close;
    private Button ok;
    public DownLoadDialog(Context context, String title) {
        mDialog = new Dialog(context, R.style.AppTheme2);
        Window window = mDialog.getWindow();
        WindowManager.LayoutParams wl = window.getAttributes();
        wl.x = 0;
        wl.y = 0;
        window.setAttributes(wl);
        window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
        window.setGravity(Gravity.CENTER);
        window.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        mDialog.setContentView(R.layout.dialog_download );
        mDialog.setCancelable(false);
        close = (Button) mDialog.findViewById(R.id.close);
        ok = (Button) mDialog.findViewById(R.id.ok);
        tv_title = (TextView) mDialog.findViewById(R.id.tv_title);
        big_title = (TextView) mDialog.findViewById(R.id.big_title);
        title.replaceAll("<br>","\n");
        tv_title.setText(title.replaceAll("\\n","\n"));
        close.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View arg0) {
                listener.closeClick();
                mDialog.dismiss();
            }
        });
        ok.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                if (listener!=null) {
                    listener.okClick();
                    mDialog.dismiss();
                }
            }
        });

    }
    public void setBigTitle(String bigTitle){
        big_title.setText(bigTitle);
    }
    public void setListener(Listener listener,String closeStr,String okStr){
        this.listener=listener;
        if (closeStr!=null) {
            close.setText(closeStr);
        }
        if (okStr!=null) {
            ok.setText(okStr);
        }
        show();
    }
    public void show(){
        if (mDialog!=null) {
            mDialog.show();
        }
    }
    public interface Listener{

        public void okClick();
        public void closeClick();

    }
}
